<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //find(): 找到满足条件的一个立即返回
        //findIndex():找到满足条件的一个，立即返回索引
        [10, 20, 30, 50, 100].find((value, index, arr) => {
            console.log(value, index, arr)
        })

        //find(): 找到满足条件的一个立即返回
        console.log([10, 20, 30, 50, 100].find((value, index, arr) => {

            return value > 10; //20

        }), )


        //findIndex():找到满足条件的一个，立即返回索引
        console.log([10, 20, 30, 50, 100].findIndex((value, index, arr) => {
            return value > 10; //1
        }))

        //应用场景
        const student = [{
            name: 'Cai',
            sex: '女',
            age: 19
        }, {
            name: 'Lily',
            age: 20,
            sex: '男'
        }, {
            name: 'LL',
            age: 22,
            sex: '男'
        }];

        console.log(student.find(value =>
            value.sex === '女'
        ))
        console.log(student.findIndex(value =>
            value.sex === '女'
        ))
    </script>
</body>

</html>